package com.doit.day06

import scala.util.Random

object _03_闭包 {
  def main(args: Array[String]): Unit = {
    val fx = (a:Int,b:Int)=>{
      a+b
    }

    val fxx = (a:Int) => {
      (b:Int)=>a+b
    }

    val res = fxx(3)(10)
    println(res)

    
    val abc = 10

    def add11(a:Int)={
      a+abc
    }


    val f = () => {
      val random: Random = new Random()
      var p = random.nextInt(10)

      val inner = () => {
        p += 1
        p
      }
      inner
    }

    val x1: () => Int = f()
    println(x1())//6   6
    println(x1())//5   7

    println("-----------")

    val x2 = f()
    println(x2())
    println(x2())
    println(x2())


  }

}
